package com.data.center.dto;


import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.data.center.util.ExcelUtils.CustomStringToListConverter;
import io.swagger.annotations.ApiModel;
import lombok.Data;

import java.util.Date;
import java.util.List;
import java.util.Objects;

@Data
@ApiModel
public class OrganizationDto extends BaseDto{

    // 忽略该字段，从EXCEL中读取时不进行反序列化
    @ExcelIgnore
    private String organizationId;

    @ExcelProperty
    private String name;

    // 自定义了一个类型转换器，将字符串转换为List<String>
    @ExcelProperty(converter = CustomStringToListConverter.class)
    private List<String> abbreviation;

    @ExcelProperty
    private String category;
    @ExcelProperty
    private String uscc;
    @ExcelProperty
    private String representative;
    @ExcelProperty
    private String description;
    @ExcelProperty
    private String country;
    @ExcelProperty
    private String divisionCode;
    @ExcelProperty
    private String address;
    @ExcelProperty
    private String postCode;

    @ExcelIgnore
    private Integer status;
    @ExcelIgnore
    private String approver;
    @ExcelIgnore
    private Date approvalTime;

    @Override
    public String toString() {
        return "OrganizationDto{" +
                "organizationId='" + organizationId + '\'' +
                ", name='" + name + '\'' +
                ", abbreviation=" + abbreviation +
                ", category='" + category + '\'' +
                ", uscc='" + uscc + '\'' +
                ", representative='" + representative + '\'' +
                ", description='" + description + '\'' +
                ", country='" + country + '\'' +
                ", divisionCode='" + divisionCode + '\'' +
                ", address='" + address + '\'' +
                ", postCode='" + postCode + '\'' +
                ", status=" + status +
                ", approver='" + approver + '\'' +
                ", approvalTime=" + approvalTime +
                '}';
    }
// Getters and setters for the above fields

    /**
     * 简称 的反序列化
     * 简称 含义为机构别名，每个机构可能同时有几种称呼，所以需要存储多值并进行序列+反序列化操作
     * 在这里不适用json方式进行序列化，由于json数据标识符较多，相对于,分割方式数据利用效率较低，且反序列化效率也较低
    **/
//    public List<String> getAbbreviation() {
//        if (abbreviation != null && !abbreviation.isEmpty()) {
//            return Arrays.asList(abbreviation.split(","));
//        } else {
//            return Collections.emptyList();
//        }
//    }

    /**
     * 简称 的序列化
     **/
//    public void setAbbreviation(List<String> abbreviations) {
//        StringBuffer stringBuffer = new StringBuffer();
//        abbreviations.forEach(item -> stringBuffer.append(item + ","));
//        abbreviation = stringBuffer.toString();
//    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof OrganizationDto)) return false;
        OrganizationDto that = (OrganizationDto) o;
        return Objects.equals(organizationId, that.organizationId) && Objects.equals(name, that.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(organizationId, name);
    }

}
